/**
 * Copyright (C) 2008 Christopher Allen Ogden
 *
 *     This file is part of Odysi.
 *
 *  Odysi is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Odysi is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Odysi.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once
#include <lua.hpp>
#include <lauxlib.h>
#include <string>
#include <boost/shared_ptr.hpp>
#include "packet.h"

namespace Lua {
    /**
     * Register a pointer with Lua.
     *
     * @param L     The Lua state.
     * @param name  The name of the variable.
     * @param p     The pointer.
     */
    void registerPointer(lua_State *L, const std::string &name, void *p);

    /**
     * Get a registered pointer from Lua.
     *
     * @param L     The Lua state.
     * @param name  The name of the variable.
     * @return      The pointer.
     */
    void *getRegisteredPointer(lua_State *L, const std::string &name);

    /**
     * Serialize the call stack from Lua into a remote call packet.
     *
     * @param L     The Lua state.
     * @return      Serialized call stack.
     */
    boost::shared_ptr<Packet> createRemoteCall(lua_State *L);

    /**
     * Process a remote call packet.
     *
     * @param L     The Lua state.
     * @param pkt   Packet to process.
     * @param conn  Optional connection (-1 for none)
     */
    void processRemoteCall(lua_State *L, const Packet &pkt, int conn);

    /**
     * Set the require path in Lua.
     *
     * @param L     The Lua state.
     */
    void setPath(lua_State *L);
}
